<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no,minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
    <meta name="apple-mobile-web-app-title" content="阿福易购">
    <meta content="telephone=no" name="format-detection" />
    <meta content="email=no" name="format-detection" />
    <!-- uc、qq浏览器 -->
    <meta name="screen-orientation" content="portrait">
    <meta name="full-screen" content="yes">
    <meta name="browsermode" content="application">
    <meta name="x5-orientation" content="portrait">
    <meta name="x5-fullscreen" content="true">
    <meta name="x5-page-mode" content="app">
    <meta name="HandheldFriendly" content="true">
    <meta name="MobileOptimized" content="320">
    <meta name="keywords" content="{{$SEO['keywords']}}"/>
    <meta name="description" content="{{$SEO['description']}}"/>
    <meta name="csrf-token" content="{{ csrf_token() }}" />
    <title>订单详情_{{$SEO['title']}}</title>
    <link rel="stylesheet" href="{{ asset('/build/css/app.min.css') }}">
</head>
<body ontouchstart="">

@inject('pictureService','App\Interfaces\PictureService')

@inject('orderService','App\Interfaces\OrderService')

@inject('refundGoodsService','App\Interfaces\RefundGoodsService')

<header class="ui-header ui-header-stable    af-header">
    <ul class="ui-row-flex">
        <li class="ui-col ui-flex ui-flex-pack-start">
            <i data-href="/my/order" class="ui-icon-return af-icon-home"></i>
        </li>
        <li class="ui-col ui-flex ui-flex-pack-center">
            <h1>订单详情</h1>
        </li>
        <li class="ui-col ui-flex ui-flex-pack-end">

        </li>
    </ul>
</header>
@if($order->count())
<footer class="ui-footer af-footer">
    <ul class="ui-tiled">

        <?php

            $pay_type = 1;

            switch ($order->pay_type) {

                case 'alipay':

                    $pay_type = 1;

                    break;

                case 'wxpay':

                    $pay_type = 3;

                    break;

                case 'pinganpay':

                    $pay_type = 4;

                    break;

                default:

                    $pay_type = 1;

                    break;
            }
        ?>
        @if($order->order_status==1)
            <li>
                <button class="ui-btn-s ui-btn-danger J-cancelOrder" data-id="{{$order->order_id}}" style="margin-top: 14px;">
                    取消
                </button>
            </li>
            <li></li>
            <li></li>
            <li>
                <button class="ui-btn-s ui-btn-default" style="margin-top: 14px;" data-id="{{$order->order_id}}" onclick="window.location.href='/pay/request/{{$order->order_id}}/{{$pay_type}}'">
                    支付
                </button>
            </li>
        @elseif($order->order_status==2)
            <li>
                @if(!$notice)
                    <button class="ui-btn-s ui-btn-default fn-btn-remind" data-id="{{$order->order_id}}" data-user="{{$user->id}}" style="margin-top: 14px; width:100%; padding:0px 10px;">
                        提醒发货
                    </button>
                @endif
            </li>
            <li></li>
            <li></li>
            <li>
                <button class="ui-btn-s ui-btn-default J-payagain" style="margin-top: 14px; width:100%; padding:0px 10px;" data-id="{{$order->order_id}}" data-goCart="true">
                    再次购买
                </button>
            </li>
        @elseif($order->order_status==3)
            <li></li>
            <li></li>
            <li></li>
            <li>
                <button class="ui-btn-s ui-btn-default J-receive" data-id="{{$order->order_id}}" style="margin-top: 14px; width:100%; padding:0px 10px;">
                    确认收货
                </button>
            </li>
        @elseif($order->order_status==4)
            <li></li>
            <li>
                @if($order->comment_status==0)
                <button data-href="/comment" class="ui-btn-s ui-btn-default" data-id="{{$order->order_id}}" style="margin-top: 14px;">
                    评价
                </button>

                @elseif($order->comment_status==1)
                    <button class="ui-btn-s ui-btn-gray" style="margin-top: 14px">已评价</button>
                @endif
            </li>
            <li>
                <button class="ui-btn-s ui-btn-danger J-delete" data-id="{{$order->order_id}}" style="margin-top: 14px;">
                    删除
                </button>
            </li>
            <li>
                <button class="ui-btn-s ui-btn-default J-payagain" style="margin-top: 14px; width:100%; padding:0px 10px;" data-id="{{$order->order_id}}" data-goCart="true">
                    再次购买
                </button>
            </li>
        @elseif($order->order_status==5)
            <li>
                <button class="ui-btn-s ui-btn-danger J-delete" data-id="{{$order->order_id}}" style="margin-top: 14px;">
                    删除
                </button>
            </li>
            <li></li>
            <li></li>
            <li></li>
        @endif
    </ul>
</footer>

<div class="ui-container"  >

    <section class="ui-my-toolbar ui-border-tb my-order-detail ">
        <h2 class="tool-item">
            <span class="order-sn">订单号 :  {{$order->order_sn}}</span>
            <span class="status">
                @if($order->order_status==1)
                <i class="icon icon-order-status icon-ord-st-pay"></i>未支付
                @elseif($order->order_status==2)
                <i class="icon icon-order-status icon-ord-st-express"></i>待发货
                @elseif($order->order_status==3)
                <i class="icon icon-order-status icon-ord-st-express"></i>待收货
                @elseif($order->order_status==4 && $order->comment_status==0)
                <i class="icon icon-order-status icon-ord-st-ok"></i>待评价
                @elseif($order->order_status==4 && $order->comment_status==1)
                <i class="icon icon-order-status icon-ord-st-ok"></i>已评价
                @elseif($order->order_status==5)
                <i class="icon icon-order-status icon-ord-st-warning"></i>订单取消
                @elseif($order->order_status=6)
                <i class="icon icon-order-status icon-ord-st-warning"></i>已退款
                @endif</span>

        </h2>
    </section>

    <section class="ui-my-toolbar ui-border-tb af-step">
        <h2 class="tool-item ">
            <span><i class="ui-icon-personal ui-tool-icon" style="color: red;margin-top: -18px;width: 20px;"></i></span>
            <span><span>{{$order->consignee}}</span><span class="af-step-phone" style="float: right;"><i></i>{{$order->mobile}}</span></span>
            <p class="ui-txt-info" style="padding-top: 5px;">
                @if(!in_array(trim($order->province), $cities))
                    {{$order->province}}
                @endif
                {{ $order->city.$order->district.$order->address }}
            </p>
        </h2>

        <b class="af-step-borderT"></b>
        <b class="af-step-borderB"></b>
    </section>

    <div class="ui-my-order ui-border-tb">
        <div class="ui-my-order-content">
            <ul class="ui-list  ui-border-tb">

                <?php $orderGoodObj=$orderService->getOrderGoods($order->order_id);?>

                @foreach($orderGoodObj as $key=>$orderGoods)

                <li class="ui-border-t" onclick="window.location.href='/goods/show/{{$orderGoods->goods_id}}'">
                    <div class="ui-list-img">
                        <span style="background-image:url({{$pictureService::thumb($orderGoods->goods_thumb, 70, 70)}})"></span>
                    </div>
                    <div class="ui-list-info">
                        <h4 class="ui-nowrap">{{$orderGoods->goods_name}} {{$orderGoods->goods_pet_name}}</h4>
                        <h4><span>¥{{$orderGoods->shop_price}}</span> ×{{$orderGoods->buy_number}} </h4>

                    </div>
                    @if($order->order_status==4)
                        <?php

                            $refundGoods = $refundGoodsService->getByOrderSnGoodsSn($order->order_sn, $orderGoods['goods_sn']);
                        ?>
                        @if($refundGoods && $refundGoods['refund_status'])

                            <div class="ui-btn ui-btn-gray" data-href="/wap/my/refund/{{$refundGoods->refund_sn}}" style="top: 15px;margin-right: 10px;">退/换货</div>
                        @else

                            <div class="ui-btn ui-btn-gray" data-href="{{route('wap.my.refund.apply',[$order->order_sn,$orderGoods['goods_id']])}}" style="top: 15px;margin-right: 10px;">退/换货</div>
                        @endif
                    @endif
                </li>

                @endforeach

            </ul>
        </div>
    </div>

    <section class="ui-my-toolbar ui-border-tb  ">
        <h2 class="tool-item ui-border-b ">
            <span>  支付方式</span>
            <span style="float: right">

                <?php
                    switch($order->pay_type){

                        case 'alipay':

                            echo '支付宝';
                        break;

                        case 'wxpay':

                            echo '微信';
                        break;

                        default:

                            echo '在线支付';
                        break;
                    }
                ?>
            </span>
        </h2>
        <h2 class="tool-item ui-border-b"><span>  配送信息</span><span style="float: right">
        @if(@$order->shipping_type)
            <?php
                switch($order->shipping_type){
                    case 'eto':
                        echo '申通';
                    break;

                    case 'yto':
                        echo '圆通';
                    break;
                }
            ?>单号：{{$order->shipping_num}}
        @endif</span></h2>
        <!-- <h2 class="tool-item ui-border-b"><span>  发票信息</span><span style="float: right">不开发票</span></h2> -->
        <h2 class="tool-item "><span>  下单时间</span><span style="float: right">{{$order->add_time}}</span></h2>
    </section>

    <section class="ui-my-toolbar ui-border-tb  " style="padding-bottom: 40px;">
        <h2 class="tool-item "><span>  金额合计</span><span style="float: right">￥{{$order->order_price}}</span></h2>
        <h2 class="tool-item"><span>  关税</span><span style="float: right">￥{{$order->order_tariff_fee}}</span></h2>
        <h2 class="tool-item "><span>  运费</span><span style="float: right">￥{{$order->shipping_fee}}</span></h2>
        <h2 class="tool-item "><span>  优惠券</span><span style="float: right">-￥{{$order->coupon_price}}</span></h2>
        <h2 class="tool-item "><span>  折扣</span><span style="float: right">-￥{{$order->discount_price}}</span></h2>
        <h2 class="tool-item ui-border-t "><span style="float: right">实付款:￥{{$order->pay_price}} </span></h2>
    </section>

</div>
@else
<div class="ui-container"  >
    <section class="ui-my-toolbar ui-border-tb my-order-detail ">
        订单不存在
    </section>
</div>
@endif


<script src="{{ asset('/build/lib/zepto.min.js') }}"></script>
<script src="{{ asset('/build/js/frozen.js') }}"></script>
<script src="{{ asset('/build/js/app.min.js') }}"></script>


<script>

    //再次购买
    $('.J-payagain').on('click', function (e) {
        e.preventDefault();

        //获取订单ID
        var btn = $(this), order_id = btn.attr('data-id'), goCart = btn.data('gocart');
        var allCartItem=$('.js-cart').find('.cart-num');

        if(typeof order_id=='undefined'||order_id==''||btn.hasClass('disabled')||btn.prop('disabled')) return false;
        btn.addClass('disabled').prop('disabled',true);
        $.ajax({
            url: '/my/order/payagain' + "?" + Math.random(),
            type: 'post',
            data: {order_id: order_id, '_token': '{{csrf_token()}}'},
            dataType: "json",
            success: function (result) {
               if (typeof result.goods_num!='undefined' && result.goods_num != ''){
                   topTip('已加入购物车',{
                      icon: 1,
                      offset:'10px',
                      time:2000
                    });
                   allCartItem.text(result.goods_num);
                   if(goCart) window.location.href='/cart';//如果按钮带data="goCart"属性，成功后跳转到购物车
               } else if(typeof result.message!='undefined' && result.message != ''){
                   topTip(result.message,{type:'warn'});
               } else{
                   topTip('操作失败，请刷新页面重试！',{type:'warn'});
               }
               btn.removeClass('disabled').prop('disabled',false);
            }

        });

    });

    //确认收货
    $('.J-receive').on('click', function (e) {
        e.preventDefault();
        //获取订单ID
        var that=$(this),order_id=that.attr('data-id');
        var dialog=$.dialog({
            title:'提示信息',
            content:'您确认已经收到货了？',
            button:['取消','确认']
        });

        dialog.on('dialog:action',function(e){
            if(e.index){
                var lk=Locked();
                $.ajax({url:'/my/order/receiveGoods?'+Math.random(),type:'post',dataType:'json',data:{order_id: order_id, '_token': '{{csrf_token()}}'},
                    success:function(res){
                        console.log(res);
                        if(res.status){
                            // that.closest('.ui-my-order').fadeOut(500,function(){$(this).remove()});
                            window.location.reload();
                        }else{
                            topTip(res.message||'取消失败',{type:'warn'});
                        }
                    },
                    error:function(e){
                        topTip(e.responseText||'取消失败',{type:'warn'});
                    },
                    complete:function(){
                        UnLocked(lk);
                    }
                })
            }
        });
    });

    //取消订单
    $('.J-cancelOrder').on('click',function(e){

        var that=$(this),id=that.attr('data-id'),reason='';
        var dialog=$.dialog({
            title:'提示信息',
            content:'确定要取消订单吗?',
            button:['取消','确认']
        });

        dialog.on('dialog:action',function(e){
            if(e.index){
                var lk=Locked();
                $.ajax({url:'/my/order/cancelOrder?'+Math.random(),type:'post',dataType:'json',data:{order_id:id,reason:reason},
                    success:function(res){
                        if(res.status){
                            that.closest('.ui-my-order').fadeOut(500,function(){$(this).remove()});
                            window.location.reload();
                        }else{
                            topTip(res.message||'取消失败',{type:'warn'});
                        }
                    },
                    error:function(e){
                        topTip(e.responseText||'取消失败',{type:'warn'});
                    },
                    complete:function(){
                        UnLocked(lk);
                    }
            })
            }
        });

    });

    //删除订单
    $('.J-delete').on('click',function(){
        var that=$(this),id=that.attr('data-id');
        var dialog=$.dialog({
            title:'提示信息',
            content:'确定要删除吗?',
            button:['取消','确认']
        });

        dialog.on('dialog:action',function(e){
            if(e.index){
                var lk=Locked();
                $.ajax({url:'/my/order/'+id,type:'delete',dataType:'json',
                    success:function(res){
                        if(res.status){
                            Jump('/my/order');
                        }else{
                            topTip(res.message||'提交失败',{type:'warn'});
                        }
                    },
                    error:function(e){
                        topTip(e.responseText||'提交失败',{type:'warn'});
                    },
                    complete:function(){
                        UnLocked(lk);
                    }
            })
            }
        });
    });

    //提醒发货
    $('.fn-btn-remind').on('click',function(e){
    var btn=$(this),order_id=btn.data('id'),user_id=btn.data('user');
    //alert(order_id);
    //console.log(order_id);
    if(btn.hasClass('disabled')) return false;
    e.preventDefault();
    $.ajax({
                url:'/my/order/remind'+"?"+Math.random(),
                type:'post',
                data:{notice_id:order_id,user_id:user_id,'_token':'{{csrf_token()}}'},
                dataType:"json",
                success:function(result){
                console.log(result);
                    if(result.status){
                    //console.log(result.status);
                        topTip("提醒成功",{offset: '10px'});
                        //layer.msg("提醒成功",{offset: '10px'});
                        btn.addClass('disabled');
                    }else{
                    }
                }
            });
    });
</script>
</body>
</html>